<?php
/**
 * Object Relational Persistence Mapping Class for table: test
 *
 * @package	com.clearhealth
 * @author	ClearHealth Inc.
 */
class CompositeService extends ORDataObject {

	/**#@+
	 * Fields of table: composite_service mapped to class members
	 */
	var $composite_service_id		= '';
	var $room_id		= '';
	var $payment_type   = '';
	var $vi_name			= '';
	var $en_name           = '';
	var $disabled   	= '';
	/**#@-*/

	const COMPOSITE_OVERAL_EYE_EXAM = 1860564;
	const COMPOSITE_REFRACTION = 1860570;
	
	/**
	 * DB Table
	 */
	var $_table = 'composite_service';

	/**
	 * Primary Key
	 */
	var $_key = 'composite_service_id';
	
	/**
	 * Internal Name
	 */
	var $_internalName = 'CompositeService';

	/**
	 * Handle instantiation
	 */
	function CompositeService() {
		parent::ORDataObject();
	}
	function get_room_id() {
		return $this->room_id;
	}

	
	public function listAll() {
		$field    =   L10nHelper::changeField(L10nHelper::getLocale(), 'name');
		
		$ds = new Datasource_sql();
		$sql = array (
			'cols'		=>	"composite_service_id, t.$field name",
			'from'		=>	"$this->_table t",
			'where' 	=>	"disabled = 0",
			'orderby'	=>	"name");
		$ds->setup($this->_db, $sql);
		return $ds->toArray('composite_service_id', 'name');
	}
	
	public function listAllFullInfo() {
		$field    =   L10nHelper::changeField(L10nHelper::getLocale(), 'name');
		
		$ds = new Datasource_sql();
		$sql = array (
			'cols'	=> "composite_service_id, T.$field AS composite_service_name,
			     R.$field AS room_name, T.payment_type, T.disabled",
			'from'	=> "$this->_table T LEFT JOIN room R ON T.room_id = R.room_id",
			'orderby'	=> "T.name");
		$ds->setup($this->_db, $sql);
		return $ds->toArray();
	}
	
	public function checkDuplicateName($name, $Id){
								
		if(isset($Id) && $Id != ''){
			$this->setup($Id);
			$old_name = $this->getLocalizedText('name');
			if($name == $old_name){
				return false;
			}
		}
		$field    =   L10nHelper::changeField(L10nHelper::getLocale(), 'name');
		$sql = array(
                    'cols'  => "t.$field name",
                    'from'  => "$this->_table t",
                    'where' => "name = '$name'"
                    );
                    
		$ds = new Datasource_sql();
		$ds->setup($this->_db, $sql);
		$result = count($ds->toArray());
		if($result == 0){
			return false;
		}
		return true;
	}

}
?>
